<?php
include'sql.php';
include'time.php';
$proposal_id=$_POST['proposal_id'];
//一页5条
$page=$_POST['page'];

//------------------------------------
//$page=1;//测试用
//$proposal_id=33;
//------------------------------------
$begin=($page-1)*5;
$sql="select * from proposal_discuss where RID='$proposal_id' order by time desc,ID desc limit 5 offset $begin ";
$result=SQL_query($sql);
$arr=SQL_turnarr($result);
//从数据库得总共条数：
$sql="select count(*) from proposal_discuss where RID='$proposal_id'";
$arr2=SQL_turnarr(SQL_query($sql));
$comments_num=$arr2[0][0];
//------------------------------------
//获得平均分
$sql="select * from proposal_main where ID='$proposal_id'";
$arr3=SQL_turnarr(SQL_query($sql));
$average_score=$arr3[0]['score_count']/$arr3[0]['score_time'];
//------------------------------------
//测试用
/*echo "<meta charset='utf-8'>";
for($i=0;$i<$count;$i++)
{
	print_r($arr[$i]);
    echo '<br>';
}*/
//------------------------------------

//返回总共多少条、返回各评论内容、评分、评论时间、

//从数据库得第page页的5条评论数组：
for($i=0;$i<5;$i++)
{
    $time=time_echo($arr[$i]['time'],2);
    $comments_array[]=array("content"=>$arr[$i]['content'],"score"=>$arr[$i]['score'],"time"=>$time);
	// $comments_array[]=array("content"=>'1',"score"=>'1',"time"=>'1');
}
// $data=array(array('comments_num'=>$comments_num),array('comments_array'=>$comments_array));
$data=array('comments_num'=>$comments_num,"average_score"=>round($average_score,1),'comments_array'=>$comments_array);
echo json_encode($data);
       
?>